#!/usr/bin/env python3

import os

def runCmd(cmd):
    cmd = cmd.split()

    if os.fork() == 0:
        os._exit(os.execvp(cmd[0], cmd))
        #  os._exit(os.execlp('bash', '-c', cmd))  #os.system
    pid, status = os.wait()

    return os.WEXITSTATUS(status)

def main():
    while True:
        cmd = input("(%s)#> " % os.getcwd()).strip()
        if cmd == 'exit':
            break
        elif cmd.startswith("cd "):
            os.chdir(cmd[3:])
        else:
            runCmd(cmd)

if __name__ == "__main__":
    main()
